/**
 * Created by dale on 2017/8/21.
 */
$(document).ready(function () {


    var form = new xhForm($('#xh_form'));
    form.parse();

    var iTPId= xhTool.getQuery('iTPId');


    $('[name=sTag]').change(function () {
        if ($('#typeTr').length > 0){
            $('#typeTr').remove();
        }
        var tag =  $(this).val();
        if (tag == 'workOrder') {
            var str ='        <tr id="typeTr">\n' +
                '                <td style="width: 75px"><label>工单类型:</label></td>\n' +
                '                <td>\n' +
                '                    <select name="iType" must="true" class="form-control">\n' +
                '                        <option value="" selected style="display: none">请选择</option>\n' ;
            for(var id in iType ) {
                str += '                 <option value="'+id+'">'+iType[id]+'</option>\n' ;
            }
            str+='                    </select>\n' +
                '                </td>\n' +
                '            </tr>';
            $('#xh_form table').append($(str));
        }
    });
    if(iTPId){
        $.ajax({
            url:modelUrl+'template/getTempInfo',
            data:{id:iTPId},
            type:'POST',
            dataType:'json',
            success:function (data) {
                form.fill(data);
                if ($('[name=iType]').length > 0) {
                    $('[name=iType]').val(data['iType']);
                }
            },
            error:function (data) {
                console.log(data);
            }
        });
    }
    
    $('#bt_modal_confirm',parent.document).click(function () {
        form.submit('bpm/template/saveTemp',{},function (res) {
            window.top.xhTop.showSuccess(res.msg);
            window.top.xhTop.getActiveFrame().obj.table.treegrid('reload', {});
            window.top.xhTop.closeModal();
        });
    });




});